layui.use('upload', function () {
    var $ = layui.jquery;
    var upload = layui.upload;

    var imgarr = []
    upload.render({
        elem: '#slide-pc',
        url: "upload",
        size: 5000,
        exts: 'jpg|png|jpeg',
        multiple: true,
        before: function (obj) {
            layer.msg('图片上传中...', {
                icon: 16,
                shade: 0.01,
                time: 0
            })
        },
        done: function (res) {
            layer.close(layer.msg());//关闭上传提示窗口
            if (res.status == 200) {
                return layer.msg(res.message);
            }

            imgarr.push(res.obj.id)

            console.log(res)
            //$('#slide-pc-priview').append('<input type="hidden" name="pc_src[]" value="' + res.filepath + '" />');

            if (imgarr.length == 1){
                $('#slide-pc-priview').append('<br/><li class="item_img"><div class="operate"><i  class="close layui-icon"><img style="height: 32px;width: 32px;" src="/images/anchor_offer_del.webp"></i></div><img src='+ res.obj.ossurl + ' class="img" ><input type="hidden" name="pc_src[]" value="' + res.obj.ossurl + '" /></li>');
            }else {
                $('#slide-pc-priview').append('<li class="item_img"><div class="operate"><i  class="close layui-icon"><img style="height: 32px;width: 32px;" src="/images/anchor_offer_del.webp"></i></div><img src='+ res.obj.ossurl + ' class="img" ><input type="hidden" name="pc_src[]" value="' + res.obj.ossurl + '" /></li>');
            }

        }
    });

    //点击多图上传的X,删除当前的图片
    $("body").on("click", ".close", function () {
        let index = $(this).closest("li").index();

        console.log(index)

        imgarr.splice(index - 1,1)

        $(this).closest("li").remove();

    });


    $("#closeDlg").click(function (){
        console.log(imgarr)
    })



});

